package ch.zbw.sysventory.agent.socketserver.handlers.impl;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;

import ch.zbw.sysventory.agent.socketserver.handlers.AbstractClientRequestHandler;

public class LatestScanResultRequestHandler extends AbstractClientRequestHandler {

	@Override
	public void handleClientRequest(String requestMessage, DataOutputStream output) throws Exception {
		String response = "";
		File xmlFile = new File("latestScanResult.xml");
		if (xmlFile.exists()) {
			StringBuffer fileData = new StringBuffer(1000);
			BufferedReader reader = new BufferedReader(new FileReader(xmlFile));
			char[] buf = new char[1024];
			int numRead = 0;
			while ((numRead = reader.read(buf)) != -1) {
				String readData = String.valueOf(buf, 0, numRead);
				fileData.append(readData);
				buf = new char[1024];
			}
			reader.close();
			response = fileData.toString();
		}
		this.sendResponseMessage(requestMessage, output, response);
	}

}
